package com.cetc.nsfx.security.vo;

import com.google.common.base.Objects;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 */
public class UserContext implements Serializable, Cloneable {

	public static final String USER_ID="SWRY_GH";

	public static final String USER_PASSWORD="USERPASSWORD";

	/**
	 *
	 */
	private static final long serialVersionUID = 9176941891434972231L;


	/** */
	private String hostName;

	/** */
	private String hostAddress;

	/** */
	private String userId;
	private String username;


	private Map<String,Object> user;


	/** */
	private transient Date operateTime;

	private boolean needValidation = true;

	public Date getOperateTime() {
		// if (null == operateTime) { //对于内部定时功能存在问题
		operateTime = new Date();
		// }
		return operateTime;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}



	/**
	 * @return the hostName
	 */
	public String getHostName() {
		return hostName;
	}

	/**
	 * @param hostName
	 *            the hostName to set
	 */
	public void setHostName(String hostName) {
		this.hostName = hostName;
	}

	/**
	 * @return the hostAddress
	 */
	public String getHostAddress() {
		return hostAddress;
	}

	/**
	 * @param hostAddress
	 *            the hostAddress to set
	 */
	public void setHostAddress(String hostAddress) {
		this.hostAddress = hostAddress;
	}


	/**
	 * @return the userId
	 */
	public String getUserId() {
		return userId;
	}

	/**
	 * @param userId
	 *            the userId to set
	 */
	public void setUserId(String userId) {
		this.userId = userId;
	}



	/**
	 * @param operateDate
	 *            the operateTime to set
	 */
	public void setOperateDate(Date operateDate) {
		this.operateTime = operateDate;
	}

	public boolean isNeedValidation() {
		return needValidation;
	}

	public void setNeedValidation(boolean needValidation) {
		this.needValidation = needValidation;
	}

	public Map<String, Object> getUser() {
		return user;
	}

	public void setUser(Map<String, Object> user) {
		this.user = user;
	}


	public UserContext clone() {
		UserContext userContext = null;
		try {
			userContext = (UserContext) super.clone();
		} catch (CloneNotSupportedException e) {
			throw new RuntimeException("UserContext  dosenot support cloneMethod");
		}
		return userContext;
	}
	
	/**
	 * 重载hashCode,只计算loginName;
	 */
	@Override
	public int hashCode() {
		return Objects.hashCode(username);
	}

	/**
	 * 重载equals,只计算loginName;
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		UserContext other = (UserContext) obj;
		if (userId == null) {
			if (other.userId != null) {
				return false;
			}
		} else if (!userId.equals(other.userId)) {
			return false;
		}
		return true;
	}



}
